package cn.jljiayu.core.api;


import lombok.Data;

@Data
public class APIResponse {

    private String respCode;

    private String respMsg;

    private Object data;

    public APIResponse() {
    }

    public APIResponse(String respCode, String respMsg) {
        this.respCode = respCode;
        this.respMsg = respMsg;
    }

    public static APIResponse success(){
        return new APIResponse("0000","success");
    }

    public static APIResponse fail(String failMsg){
        return new APIResponse("9999",failMsg);
    }

    public static APIResponse toAPIResponse(Object data) {
        APIResponse response = new APIResponse();
        response.setData(data);
        response.setRespCode(ApiResEnums.SUCCESS.getRespCode());
        response.setRespMsg(ApiResEnums.SUCCESS.getRespMsg());
        return response;
    }

    public boolean isSuccess(){
        return "0000".equals(respCode);
    }
}
